package com.umakr.ax.app.web;

import com.umakr.ax.app.service.AppUploadService;
import com.umakr.ax.common.model.AppVersion;
import com.umakr.ax.core.base.AbstractController;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * @author tangtengfei
 */
@Controller
@RequestMapping("/api/web/versionUpload")
public class VersionUploadController extends AbstractController {
    @Autowired
    AppUploadService appUploadService;
    /**
     * 上传apk文件至本地
     * @param modelMap
     * @return
     */
    @ApiOperation(value = "本地文件上传")
    @RequestMapping("/apkUpload")
    @ResponseBody
    public Object fileUpload(ModelMap modelMap,@RequestParam("file") MultipartFile file)  throws IOException {
        return setSuccessModelMap(modelMap,appUploadService.fileUpload(file));
    }

    @ApiOperation(value = "历史版本列表")
    @GetMapping(value = "/listHisVersion")
    @ResponseBody
    public Object listHisVersion(ModelMap modelMap,@RequestParam(name = "versionCode") Integer versionCode,
                                 @RequestParam(name = "versionType") Integer versionType) {
        return setSuccessModelMap(modelMap,appUploadService.listHisVersion(versionCode,versionType));
    }

    @ApiOperation(value = "新增版本")
    @GetMapping("/saveNewVersion")
    @ResponseBody
    public Object saveNewVersion(ModelMap modelMap, AppVersion appVersion) {
        return setSuccessModelMap(modelMap,appUploadService.saveNewVersion(appVersion));
    }

    @ApiOperation(value = "删除apk")
    @GetMapping("/delectApk")
    @ResponseBody
    public Object delectApk(ModelMap modelMap, @RequestParam("apkUrl") String apkUrl) {
        return setSuccessModelMap(modelMap,appUploadService.delectApk(apkUrl));
    }

}
